def f(n):
    d=2
    while d*d <=n:
        if n % d ==0:
            return False
        d+=1
    return True 
d=['zero','one','two','three','four','five','six','seven','eight','nine']
a=input().split()
if len(a) !=3 or a[0] not in d or a[1] not in d or a[2] not in d :
    print('Wrong input')
else:
    n=int(str(d.index(a[0]))+str(d.index(a[1]))+str(d.index(a[2])))
    for i in range (1,1000):
        if f (n-i):
            print(n-i)
            break
        if f (n+i):
            print(n+i)
            break
